#include <iostream>
#include <signal.h>
#include <unistd.h>
#include <sys/types.h>

void PrintPending(sigset_t& pending)
{
    std::cout<<"process["<<getpid()<<"] pending "<<std::endl;

    for(int i=31;i>=1;i--)
    {
        if(sigismember(&pending,i))
        {
            std::cout<<1;
        }
        else
        {
            std::cout<<0;
        }

    }
    std::cout<<std::endl;
}
void handler(int sig)
{
    std::cout<<"sig"<<"号信号被递达"<<std::endl;
    std::cout<<"##################"<<std::endl;
    sigset_t pending;
    sigpending(&pending);
    PrintPending(pending);
    std::cout<<"##################"<<std::endl;

}


int main()
{
    signal(SIGINT,handler);

    sigset_t block_set,old_set;
    sigemptyset(&block_set);
    sigemptyset(&old_set);

    sigaddset(&block_set,SIGINT);//这里没有修改到真正的内核block表

    sigprocmask(SIG_BLOCK,&block_set,&old_set);//这里修改了真正的内核block表

    int cnt=0;

    while(1)
    {
        sigset_t pending;
        sigpending(&pending);

        PrintPending(pending);
        cnt++;

        if(cnt==10)
        {
            std::cout<<"解除对2号信号的屏蔽"<<std::endl;
            sigprocmask(SIG_SETMASK,&old_set,nullptr);
        }

        sleep(1);
    }

    return 0;

}